/**
 * Created by 준영 on 2014-03-29.
 */
function callAjax(callType, callUrl, parameter, callback)
{
    $.ajax({
        type: callType,
        url:callUrl,
        data: parameter
    })
        .done(function(res){
            callback(res);
        })
        .fail(function(err){
            callback(err);
        });
};

function leadingZeros(n, digits) {
    var zero = '';
    n = n.toString();

    if (n.length < digits) {
        for (i = 0; i < digits - n.length; i++)
            zero += '0';
    }
    return zero + n;
}

function isoDateToDate(isoDate)
{
    var startTime = new Date(isoDate );
    startTime =   new Date( startTime.getTime() + ( startTime.getTimezoneOffset() * 60000 ) );

    var totalMilliSecond = startTime.getTime();

    var date  = new Date(totalMilliSecond );
    return date;
}

function getParameterByName(name)
{
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};

function getHost() {
    return "http://119.207.203.170";
}
function isEmpty(input)
{
    var blank_pattern = /[\s]/g;
    if(blank_pattern.test(input) == true){
        alert('공백은 사용할 수 없습니다.');
        return false;
    }

    var special_pattern = /[`~!@#$%^&*|\\\'\";:\/?]/gi;
    if( special_pattern.test(input) == true ){
        alert('특수문자는 사용할 수 없습니다.');
        return false;
    }
return true;
};
window.addEventListener('load', function() {

    setTimeout(scrollTo, 0, 0, 1);

}, false);

$(document).ready(function()
{


    if(typeof user == 'undefined')
    {
        $('#btnTopLogout').css("display", 'none');
        $('#btnTopLogin').css("display", '');
    }
    else
    {
        $('#btnTopLogout').css("display", '');
        $('#btnTopLogin').css("display", 'none');
        $('#layoutUser').text(userInfo.nickname.toString());


    }




   $('#btnTopLogin').on('click', function()
   {
       window.location.href=("/login");
   });

    $('#btnTopLogout').on('click', function()
    {
        callAjax('GET','/api/logout',"", function(res) {
            location.href = "/";
        });
      //  window.location.href=("/login");
    });
});